$(function(){
//    $.ajaxSetup({
//        beforeSend: function(){
//            $('#ajax-loading').fadeIn();    
//        },
//        complete: function(){
//            $('#ajax-loading').fadeOut();   
//        }
//    });

    $('#ajax-loading #close-loading').click(function(){
        $('#ajax-loading').fadeOut();    
    });
    
    /////////////////////// REQUIRE LOGIN /////////////////
    $('.require-login').bind('click blur focus keypress keyup paste change', function(e){
        e.preventDefault();
        $('#modal-login').modal();
        if($(this).attr('href') != undefined){
            $.cookie('loginRedirect', $(this).attr('href'), { path: '/' });
        }
    });
    $('#modal-login').on('hide.bs.modal', function () {
        $.cookie('loginRedirect', null, { path: '/' });
    });

    // tooltip
    $('[rel=tooltip]').tooltip();

    // popover
    $('[rel=popover]').popover({
        html : true,        
        content: function() {
            return $('#'+$(this).attr('id')+'-popover').html();
        },
    });
    $("[data-toggle=popover]").popover();
      
    // format number
    $('.number-format').each(function() {
        var number = parseInt(($(this).text() + '').replace(/[^\d]/g, '')); 
        number = number_format(number, 0, '', '.');
        $(this).text(number);
    });

    $("input.numeric").numeric();
    $("input.numeric.format").bind('keypress keyup paste', function(e){
        if($(this).val() != ''){
            var val = parseInt(($(this).val() + '').replace(/[^\d]/g, ''));
            var valFormat = number_format(val, 0, '.', '.');
            valFormat = valFormat != '0' ? valFormat : '';
            $(this).val(valFormat);
        }
    });
})


function scrollToAnchor(selector, top){
    top = typeof top !== 'undefined' ? top : 100; 
    $('html,body').animate({scrollTop: $(selector).offset().top - top},'fast');
}

//http://www.tinymce.com/tryit/classic.php
//http://www.tinymce.com/wiki.php/Configuration
var tinyMceConfig = {
    mode : "textareas",
    selector: "textarea.editor",
    
//    plugins: [
//        "advlist autolink autosave link image lists charmap print preview hr anchor",
//        "wordcount visualblocks visualchars code fullscreen media nonbreaking",
//        "table directionality textcolor paste textcolor"
//    ],
//    toolbar1: "bold italic underline strikethrough fontsizeselect | link unlink image | alignleft aligncenter alignright | bullist numlist blockquote hr | removeformat code fullscreen | restoredraft",

    plugins: ["link image lists paste"],
    toolbar: "bold italic underline strikethrough styleselect | bullist numlist | link unlink image | alignleft aligncenter alignright",
    language : 'vi',

    menubar: false,
    statusbar : false,
    remove_script_host : true,
    toolbar_items_size: 'small',
    relative_urls : false,

    force_p_newlines: false,
    forced_root_block: false,
    force_hex_style_colors : false,
    
    paste_as_text: true,
    style_formats: [
        //{title: 'Chữ nhỏ', inline: 'span', styles: {'font-size': '12px'}},
        {title: 'Chữ thường', inline: 'span', styles: {'font-size': '14px'}},
        {title: 'Chữ to vừa', inline: 'span', styles: {'font-size': '20px'}},
        {title: 'Chữ to nhất', inline: 'span', styles: {'font-size': '26px'}},
    ],

    formats : {
        bold : {inline : 'strong'},
        italic : {inline : 'em'},
        underline : {inline : 'u'},
        strikethrough : {inline : 'del'},
        fontsize: {
            
            
        }
    },


};


function myGrowl(msg, type, title) {
    msg = typeof msg !== 'undefined' ? msg : 'Thông báo'; 
    type = typeof type !== 'undefined' ? type : 'success'; 
    title = typeof title !== 'undefined' ? title : ''; 

    $.jGrowl(msg, {
        header: title,
        position: "bottom-right",
        life: 10000,
        group: type, 
        theme: "jgrowl",
        themeState: "jgrowl-state",
        corners: "5px",
    }); 
}

function getPriceLabel($price){
    return number_format($price, 0, '', '.')+'₫';
}
